package com.example.jiancaiwang.controller;

import com.example.jiancaiwang.Api;
import com.example.jiancaiwang.callback.MyOkhttpCallBack;
import com.example.jiancaiwang.model.HomeModel;
import com.example.jiancaiwang.view.IView;

/**
 * controller：管理model和view：让model获取数据，同志view做出UI刷新
 */
public class HomeController {
    private HomeModel homeModel;//model
    private IView iView;//view

    public HomeController(IView iView) {
        this.iView = iView;
        homeModel = new HomeModel();
    }
    //获得轮播图数据
    public void getBannerData(){
        iView.showProgress();
        homeModel.getBannerData(Api.HOME_BANENR, new MyOkhttpCallBack() {
            @Override
            public void onError(String message) {
                iView.onError();
                iView.hideProgress();
            }

            @Override
            public void onOk(String json) {
                iView.onOk(json,Api.TYPE_HOME_BANNER);
                iView.hideProgress();

            }
        });

    }
    //获得menu数据
    public void getMenuData(){
        iView.showProgress();
        homeModel.getBannerData(Api.HOME_MENU, new MyOkhttpCallBack() {
            @Override
            public void onError(String message) {
                iView.onError();
                iView.hideProgress();
            }

            @Override
            public void onOk(String json) {
                iView.onOk(json,Api.TYPE_HOME_MENU);
                iView.hideProgress();

            }
        });

    }
    //获得分类数据
    public void getTypeData(){
        iView.showProgress();
        homeModel.getBannerData(Api.HOME_TYPE, new MyOkhttpCallBack() {
            @Override
            public void onError(String message) {
                iView.onError();
                iView.hideProgress();
            }

            @Override
            public void onOk(String json) {
                iView.onOk(json,Api.TYPE_HOME_TYPE);
                iView.hideProgress();

            }
        });

    }



}
